package com.ruoyi.grids.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.grids.domain.CabinetGrids;
import com.ruoyi.grids.service.ICabinetGridsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 柜格状态Controller
 *
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/grids/grids")
public class CabinetGridsController extends BaseController
{
    @Autowired
    private ICabinetGridsService cabinetGridsService;

    /**
     * 查询柜格状态列表
     */
    @PreAuthorize("@ss.hasPermi('grids:grids:list')")
    @GetMapping("/list")
    public TableDataInfo list(CabinetGrids cabinetGrids)
    {
        startPage();
        List<CabinetGrids> list = cabinetGridsService.selectCabinetGridsList(cabinetGrids);
        return getDataTable(list);
    }

    /**
     * 导出柜格状态列表
     */
    @PreAuthorize("@ss.hasPermi('grids:grids:export')")
    @Log(title = "柜格状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CabinetGrids cabinetGrids)
    {
        List<CabinetGrids> list = cabinetGridsService.selectCabinetGridsList(cabinetGrids);
        ExcelUtil<CabinetGrids> util = new ExcelUtil<CabinetGrids>(CabinetGrids.class);
        util.exportExcel(response, list, "柜格状态数据");
    }

    /**
     * 获取柜格状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('grids:grids:query')")
    @GetMapping(value = "/{gridId}")
    public AjaxResult getInfo(@PathVariable("gridId") Long gridId)
    {
        return success(cabinetGridsService.selectCabinetGridsByGridId(gridId));
    }

    /**
     * 新增柜格状态
     */
    @PreAuthorize("@ss.hasPermi('grids:grids:add')")
    @Log(title = "柜格状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CabinetGrids cabinetGrids)
    {
        return toAjax(cabinetGridsService.insertCabinetGrids(cabinetGrids));
    }

    /**
     * 修改柜格状态
     */
    @PreAuthorize("@ss.hasPermi('grids:grids:edit')")
    @Log(title = "柜格状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CabinetGrids cabinetGrids)
    {
        return toAjax(cabinetGridsService.updateCabinetGrids(cabinetGrids));
    }

    /**
     * 删除柜格状态
     */
    @PreAuthorize("@ss.hasPermi('grids:grids:remove')")
    @Log(title = "柜格状态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gridIds}")
    public AjaxResult remove(@PathVariable Long[] gridIds)
    {
        return toAjax(cabinetGridsService.deleteCabinetGridsByGridIds(gridIds));
    }
}
